package com.memory;

import java.nio.ByteBuffer;
import java.util.ArrayList;

/**
 * @author: csh
 * @Date: 2021/5/13 18:37
 * @Description:OOM 模拟直接内存溢出
 *
 * Exception in thread "main" java.lang.OutOfMemoryError: Direct buffer memory
 */
public class BufferTest2 {

    private static final int BUFFER =1024 * 1024 * 20;

    public static void main(String[] args) {
        ArrayList<ByteBuffer> list = new ArrayList <>();
        int count = 0;
        try {
            while (true){
                ByteBuffer byteBuffer = ByteBuffer.allocateDirect(BUFFER);
                list.add(byteBuffer);
                Thread.sleep(100);
            }
        }catch (Exception e){
            System.out.println("总共打印");
            e.printStackTrace();
        }
    }
}
